//
//  MainNaviController.swift
//  SinaWeiBo
//
//  Created by Leon 笑 竹 on 2017/7/31.
//  Copyright © 2017年 Leon 笑 竹. All rights reserved.
//

import UIKit

class MainNaviController: UINavigationController {

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        //隐藏导航条
        navigationBar.isHidden = true
        
        //如果不是栈底控制器就需要隐藏底部的tabbar
        if childViewControllers.count > 0 {
            //隐藏底部的tabbar
            viewController.hidesBottomBarWhenPushed = true
            
            //如果是多页数，返回按钮显示
            if let vc = viewController as? BaseViewController  {
                
                var title = "返回"
                
                //如果自控制器是1，那么久显示栈底控制器标题
                if childViewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? "返回"
                }
                
                vc.naviItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popBack),isBack : true)
            }
        }
              
        super.pushViewController(viewController, animated: true)

    }
    
    @objc fileprivate func popBack() {
        self.popViewController(animated: true)
    }

}
